<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
    <meta charset="UTF-8"/>
    <title>Title</title>
    <!-- load css -->
    <link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/css/font/iconfont.css}" media="all"/>
    <link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/js/layui/css/layui.css}"  media="all"/>
    <link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/css/main.css}" media="all"/>
    <link rel="stylesheet" type="text/css" th:href="@{/plugin/bootstrap/bootstrap/css/bootstrap.min.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/plugin/bootstrap-table/bootstrap-table.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/css/table.css}"  media="all"/>
    <link rel="stylesheet" type="text/css" th:href="@{/plugin/bootstrap/bootstrap/css/bootstrap.min.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/js/select2/css/select2.css}" media="all"/>

</head>

<body>
<div class="layui-fluid larry-wrapper">
    <div class="layui-row layui-col-space30">
        <div class="layui-col-xs24">
            <section class="panel panel-padding">
<form action="" class="layui-form layui-form-pane" id="myform">
    <legend>供应商信息</legend>
    <input type="hidden" name="sshzid">
    <div class="layui-form-item">
	<div class="layui-inline">
                        <label class="layui-form-label">货主名称</label>
                        <div class="layui-input-inline">
                        <input type="text" class="layui-input" th:value="${sshzid}"id="sshzid" readonly/>
                        </div>
     </div>
    <div class="layui-inline">
        <label class="layui-form-label">供应商名称</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="mc" id="mc" lay-verify="required"  placeholder="请输入供应商名称" />
        </div>
    </div>

    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">供应商编号</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="bh" id="bh" lay-verify="required" placeholder="请输入供应商编号"/>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">联系人</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" name="lxr" id="lxr" placeholder="请输入联系人" />
            </div>
        </div>
    </div>
    <div class="layui-form-item">
    <div class="layui-inline">
        <label class="layui-form-label">详细地址</label>
       <div class="layui-input-inline">
            <input type="text" name="xxdz" placeholder="请输入详细地址" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">电话1</label>
        <div class="layui-input-inline">
            <input type="text" name="dh1" placeholder="请输入电话" autocomplete="off" class="layui-input">
        </div>
    </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">省</label>
            <div class="layui-input-inline">
                <select lay-ignore="lay-ignore" class="js-data-example-ajax" name="sheng" id="sheng" style="width: 193px"></select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">市</label>
            <div class="layui-input-inline">
                <select lay-ignore="lay-ignore" class="cs" name="cs" id="shi" style="width: 193px"></select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">邮编</label>
            <div class="layui-input-inline">
                <input type="text" name="yb" placeholder="请输入邮编" autocomplete="off" class="layui-input">
            </div>
        </div>
    <div class="layui-inline">
        <label class="layui-form-label">电话2</label>
        <div class="layui-input-inline">
            <input type="text" name="dh2" placeholder="电话2"  autocomplete="off" class="layui-input">
        </div>
    </div>
    </div>
    <div class="layui-form-item">
    <div class="layui-inline">
        <label class="layui-form-label">传真</label>
        <div class="layui-input-inline">
            <input type="text" name="cz" placeholder="请输入传真"autocomplete="off" class="layui-input">
        </div>
    </div>
    </div>
    <div class="layui-form-item" style="float: right;">
        <div class="layui-input-block">
            <button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="addsupplier">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
            </section>
        </div>
    </div>
</div>
</body>
<div th:include="public/public_js::public_js"></div>
<script th:src="@{/plugin/beyond/assets/js/fuelux/wizard/wizard-custom.js}"></script>
<script>

    $(function () {
        $('.js-data-example-ajax').select2({
            ajax: {
                url: '/zxsswms/wmsownersupplier/searchsheng',
                dataType: 'json',
                type: 'POST',
                contentType: "application/json",
                data: function (params) {
                    var query = {
                        mc: params.term
                    };
                    return JSON.stringify(query);
                },
                processResults: function (data) {
                    var arr= new Array();
                    console.log('data', data);
                    if(data){
                        for (var i=0;i<data.length;i++){
                            arr.push({id:data[i].id,text:data[i].mc});
                        }
                    }
                    console.log(arr);
                    // Tranforms the top-level key of the response object from 'items' to 'results'
                    return {
                        results: arr
                    };
                },
                cache: true
            },
            language: "zh-CN",
            placeholder: '请输入查询字段',
            allowClear: true
        });
        $('.cs').select2({
            ajax: {
                url: '/zxsswms/wmsownersupplier/searchshi',
                dataType: 'json',
                type: 'POST',
                contentType: "application/json",
                data: function (params) {
                    var query = {
                        mc: params.term,
                        citye_parent_id:$('.js-data-example-ajax').val()
                    };
                    return JSON.stringify(query);
                },
                processResults: function (data) {
                    var arr= new Array();
                    console.log('data', data);
                    if(data){
                        for (var i=0;i<data.length;i++){
                            arr.push({id:data[i].id,text:data[i].mc});
                        }
                    }
                    console.log(arr);
                    // Tranforms the top-level key of the response object from 'items' to 'results'
                    return {
                        results: arr
                    };
                },
                cache: true
            },
            language: "zh-CN",
            placeholder: '请输入查询字段',
            allowClear: true
        });
    })
    layui.use(['myform','zzpUtils','form'],function () {
        var form = layui.form,
            zzpUtils = layui.zzpUtils;
        form.on("submit(addsupplier)",function(data){
            if($("#sheng").val()==null) {
                layer.msg("省不可为空");
            }else if($("#shi").val()==null){
                layer.msg("市不可为空");
            }else {
                zzpUtils.confirm("是否确定添加", function (index) {
                    zzpUtils.action({
                        url: "/wmsownersupplier/add",
                        data: JSON.stringify(data.field),
                        success: function (data) {
                            setTimeout(function () {
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                                if(data.message!=""){
                                    top.layer.msg(data.message);
                                }else{
                                    top.layer.msg(data.title);
                                }
                            }, 500);
                        }, error: function (xhr, textStatus) {
                            console.log(textStatus);
                            console.log(xhr);
                        }
                    })
                })
            }
            return false;

        });
    });
</script>
</html>